package solution;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-21
 * Time: 17:33
 */

//https://leetcode.cn/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/submissions/396591953/
class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}

class Solution5 {
    public int[] reversePrint(ListNode head) {
        ListNode newHead = null;
        ListNode cur = head;
        int count = 0;
        while (cur != null) {
            ListNode temp = cur.next;
            cur.next = newHead;
            newHead = cur;
            cur = temp;
            count++;
        }
        int[] arr = new int[count];
        for (int i = 0; i < count; i++) {
            arr[i] = newHead.val;
            newHead = newHead.next;
        }
        return arr;
    }
}
